package com.balabala.gym_goods.controller.admin;

import com.balabala.gym_enum.ResultEnum;
import com.balabala.gym_goods.pojo.dto.CoachScheduleDto;
import com.balabala.gym_goods.pojo.dto.ScheduleAddDto;
import com.balabala.gym_goods.pojo.vo.CourseAndCoachVo;
import com.balabala.gym_goods.pojo.vo.CourseVo;
import com.balabala.gym_goods.service.CoachScheduleService;
import com.balabala.result.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author fsj
 * @date 2023/5/5 19:14
 */
@RestController
@Slf4j
@CrossOrigin
@Api(tags = "私教管理后台接口（暂停）")
@RequestMapping("/admin/coachSchedule")
public class CoachScheduleController {

    @Autowired
    private CoachScheduleService coachScheduleService;


    @GetMapping(value = "/findAll")
    @ApiOperation(value = "查询所有私教信息")
    public Result findAll() {
        return Result.ok(ResultEnum.GENERALLY_SUCCESS, coachScheduleService.list());
    }

    @PostMapping(value = "/add")
    @ApiOperation(value = "添加私教信息")
    public Result add(@RequestBody @Validated CoachScheduleDto coachScheduleDto) {
        log.info("添加一条私教课程信息");

        return Result.ok(ResultEnum.GENERALLY_SUCCESS,coachScheduleService.addCoachSchedule(coachScheduleDto));
    }


    @DeleteMapping(value = "/deleteById")
    @ApiOperation(value = "根据id删除私教信息")
    public Result deleteById(@RequestParam Long id) {
        log.info("根据id删除私教信息");
        return Result.ok(ResultEnum.GENERALLY_SUCCESS,coachScheduleService.removeById(id));
    }


    @PostMapping(value = "update")
    @ApiOperation(value = "修改私教信息")
    public Result update(@RequestBody CoachScheduleDto coachScheduleDto) {
        log.info("修改私教信息：{}",coachScheduleDto.toString());
        return Result.judge(coachScheduleService.updateById(coachScheduleDto));
    }


    @PostMapping(value = "/schedule")
    @ApiOperation(value = "添加排课信息")
    public Result schedule(@RequestBody @Validated ScheduleAddDto scheduleAddDto) {
        log.info("添加一条私教信息");

        return Result.ok(coachScheduleService.addSchedule(scheduleAddDto));
    }

    @GetMapping("/findCourseAndCoach")
    @ApiOperation("查询所有课程和私教信息")
    public Result findCourseAndCoach() {
        List<CourseAndCoachVo> courseAndCoach=coachScheduleService.findCourseAndCoach();
        return Result.ok(ResultEnum.GENERALLY_SUCCESS, courseAndCoach);
    }


}
